import "package:flutter/material.dart";

class ActionBarWidget extends StatefulWidget {
  final String title;
  final String right;
  final Function rightOnPressed;

  const ActionBarWidget({Key key, this.title, this.right, this.rightOnPressed})
      : super(key: key);

  @override
  _ActionBarWidgetState createState() =>
      _ActionBarWidgetState(this.title, this.right, this.rightOnPressed);
}

class _ActionBarWidgetState extends State<ActionBarWidget> {
  final String _title;
  final String _right;
  final Function _rightOnPressed;

  _ActionBarWidgetState(this._title, this._right, this._rightOnPressed)
      : super();

  @override
  Widget build(BuildContext context) {
    return new Container(
      height: 50,
      color: Colors.amber,
      child: Flex(direction: Axis.horizontal, children: <Widget>[
        Expanded(
            flex: 1,
            child: Container(
              color: Colors.green,
              child: IconButton(
                  onPressed: () => Navigator.pop(context),
                  icon: Icon(Icons.arrow_back)),
            )),
        Expanded(
            flex: 8,
            child: Container(
                color: Colors.redAccent,
                child: Text(
                  _title,
                  textAlign: TextAlign.center,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                    fontSize: 20.0,
                    color: Colors.black,
                  ),
                ))),
        Expanded(
          flex: 1,
          child: ConstrainedBox(
            constraints: BoxConstraints(
                minWidth: double.infinity, minHeight: double.infinity),
            child: FlatButton(
                onPressed: () => _rightOnPressed,
                child: Text(
                  _right,
                  textAlign: TextAlign.center,
                  style: TextStyle(
                      fontSize: 18.0,
                      color: Colors.grey,
                      background: new Paint()..color = Colors.deepPurpleAccent),
                )),
          ),
//          child: Container(
//            color: Colors.lightBlue,
//            child: FlatButton(
//                onPressed: () => _rightOnPressid,
//                child: Text(
//                  _right,
//                  textAlign: TextAlign.center,
//                  style: TextStyle(
//                      fontSize: 18.0,
//                      color: Colors.grey,
//                      background: new Paint()..color = Colors.deepPurpleAccent),
//                )),
//          ),
        ),
      ]),
    );
  }
}
